package org.compression.thread;

import java.io.File;

import org.compression.mapper.SearchMapper;
import org.compression.util.PdfUtil;
import org.model.MedicalScience;
import org.springframework.beans.factory.annotation.Autowired;

public class InsertThread implements Runnable {

	
	
	public File  pdfFile;
	public int startPage;
	public int endPage;
	public String id;
	
	@Autowired
	SearchMapper mSearchMapper;
	
	
	public InsertThread(File pdfFile, int startPage, int endPage,SearchMapper mSearchMapper,String id) {
		super();
		this.pdfFile = pdfFile;
		this.startPage = startPage;
		this.endPage = endPage;
		this.mSearchMapper=mSearchMapper;
		this.id=id;
	}




	@Override
	public void run() {
		try {
			String pdfContext=PdfUtil.readFdf(pdfFile,startPage,endPage);
			MedicalScience mMedicalScience=new MedicalScience();
			mMedicalScience.setContent(pdfContext);
			mMedicalScience.setPage(startPage);
			mMedicalScience.setMagazine_id(id);
			mSearchMapper.insertMedicalScience(mMedicalScience);
			
			System.out.println(Thread.currentThread().getName()+"页码："+startPage+"      :"+pdfContext);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
